<template>
  <div class="main p-20">
    <div class="aboutusTitle">
      <i class="el-icon-s-home"></i>
      地产分类
    </div>
    <div
      class="propertyDetail"
      v-for="item in classList"
      :key="item.id"
      @click="clickFn(item.id)"
    >
      <div class="image">
        <img v-fixImg="require('@/assets/no.png')" :src="item.image" alt="" />
      </div>
      <div class="content">
        <div class="title">
          <b>{{ item.title }}</b>
        </div>
        <div class="desc">{{ item.desc }}</div>
      </div>
    </div>
    <p v-if="!classList.length" class="nothing">暂无数据</p>
    <el-row type="flex" justify="center">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage"
        :page-size="pageSize"
        layout="total, prev, pager, next"
        :total="total"
      >
      </el-pagination>
    </el-row>
  </div>
</template>

<script>
import { getCategoryList, getCategoryCount } from "@/api";
export default {
  data() {
    return {
      classList: [],
      total: 0,
      pageSize: 2,
      currentPage: 1,
      start: 0,
    };
  },
  created() {
    this.getCategoryList();
  },
  methods: {
    async getCategoryList() {
      const { data } = await getCategoryList({
        _limit: this.pageSize,
        _start: this.start,
      });
      this.classList = data;
      const res = await getCategoryCount();
      this.total = res.data;
    },
    clickFn(id) {
      this.$router.push({
        path: "/index/propertyList",
        query: {
          propertyId: id,
        },
      });
    },
    handleCurrentChange(currentPage) {
      this.currentPage = currentPage;
      this.start = (this.currentPage - 1) * this.pageSize;
      this.getCategoryList();
    },
  },
};
</script>

<style lang="less" scoped>
.propertyDetail {
  padding: 10px 0;
  display: flex;
  border: 1px solid #ccc;
  height: 200px;
  cursor: pointer;
  .image {
    padding: 10px 0;
    width: 300px;
    img {
      object-fit: cover;
      padding: 0 50px;
      border-right: 1px solid #ccc;
      width: 200px;
      height: 180px;
      vertical-align: middle;
    }
  }
  .content {
    flex: 1;
    padding: 20px;
    text-align: center;
    .title {
      padding: 10px 0;
      font-size: 20px;
    }
    .desc {
      text-align: left;
      text-indent: 2em;
    }
  }
}
</style>